package lion.demo.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lion.framework.core.web.anno.Namespace;
import lion.framework.core.web.anno.Path;
import lion.framework.core.web.anno.Result;
import lion.framework.core.web.anno.View;
import lion.framework.core.web.request.Request;
import lion.framework.core.web.views.ResultType;

@Namespace("/demo")
public class SimpleAction {

	@Path("/{id:int}")
	@Result(@View(name = "success", type = ResultType.JSON))
	public String demo1(Request request) {

		System.out.println("the id is :" + request.getInt("id"));
		request.addModel("msg", "the id is " + request.getInt("id"));

		return "success";
	}

	@Path("/demo2")
	@Result(@View("/WEB-INF/t.jsp"))
	public String demo2() {

		return "success";
	}

	@Path("/demo3")
	@Result(@View("/WEB-INF/{name}.jsp"))
	public String demo3(Request request) {

		request.addModel("name", "test");
		return "success";
	}

	@Path("/demo4")
	@Result(@View("/WEB-INF/orig.jsp"))
	public String demo3(HttpServletRequest request, HttpServletResponse response) {

		// do some thing
		return "success";
	}

	@Path("/error")
	@Result(@View("/WEB-INF/orig.jsp"))
	public String exception(HttpServletRequest request, HttpServletResponse response) {

		throw new RuntimeException("this is a runtime exception with default exception handler");
	}

}
